package com;

import com.mapper.WorkerMapper;
import com.pojo.Worker;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class WorkerTest {
    @Test
    public void findWorkerByidTest() {
        SqlSession session = MyBatisUtils.getSession();
        WorkerMapper woker = session.getMapper(WorkerMapper.class);
        Worker worker =woker.SelectWorkey(2);
        System.out.println(worker);
        session.close();
    }
    @Test
    public void findWorkerTest() {

        SqlSession session = MyBatisUtils.getSession();

        WorkerMapper mapper = session.getMapper(WorkerMapper.class);
        Worker worker = new Worker();
        worker.setName("赵六");
        worker.setAge(19);
        worker.setSex("男");
        worker.setWorkerId(1004);
        int restr = mapper.insertWorkey(worker);
        if(restr>0){
            System.out.println("插入成功");
        }else {
            System.out.println("插入失败");
        }
        System.out.println(worker);
        session.commit();
        session.close();
    }
    @Test
    public void findupdate() {

        SqlSession session = MyBatisUtils.getSession();

        WorkerMapper mapper = session.getMapper(WorkerMapper.class);
        Worker worker = new Worker();
        worker.setId(4);
        worker.setName("钱七");
        worker.setAge(111);
        worker.setSex("男");
        worker.setWorkerId(1005);
        int restr = mapper.updateWorkey(worker);
        if(restr>0){
            System.out.println("更新成功");
        }else {
            System.out.println("更新失败");
        }
        System.out.println(worker);
        session.commit();
        session.close();
    }
    @Test
    public void finddelect(){
        SqlSession session =MyBatisUtils.getSession();
        WorkerMapper mapper = session.getMapper(WorkerMapper.class);

        int restr =mapper.deleteWorkey(4);

        if(restr>0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        session.commit();
        session.close();



    }
}
